//
//  ZLViewController.swift
//  BasicProduct
//
//  Created by itzhaolei on 2021/8/27.
//

import Foundation
import ZLNavigationBar

open class ZLViewController: UIViewController {
    
    open var navTitle: String = "" {
        didSet {
            navBar.actionBar?.titleView?.titleLabel?.text = navTitle
        }
    }
        
    open lazy var navBar: ZLNavigationBar = {
        let navBar = ZLNavigationBar()
        return navBar
    }()
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        addSubviews()
        addConstraints()
        addActions()
    }
    
    open func addSubviews() {
        
    }
    
    open func addConstraints() {
        
    }
    
    open func addActions() {
        
        // 返回上级
        navBar.actionBar?.leftItem?.click = {[weak self] in
            guard let self = self else { return }
            self.goback()
        }
        
    }
    
    @objc open func goback(animated: Bool = true) {
        if navigationController == nil {
            dismiss(animated: animated, completion: nil)
            return
        }
        if navigationController?.viewControllers.first == self {
            dismiss(animated: animated, completion: nil)
            return
        }
        navigationController?.popViewController(animated: animated)
    }
    
    open func push(vc: UIViewController) {
        navigationController?.pushViewController(vc, animated: true)
    }
    
}
